home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / smaltalk / gnu_st.lha / gnu_st / smalltalk-1.1.1 / WordMemory.st < prev    next >
Text File  |  1991-09-12  |  3KB  |  91 lines

  1. "======================================================================
  2. |
  3. |   Word oriented memory definitions
  4. |
  5.  ======================================================================"
  6.  
  7.  
  8. "======================================================================
  9. |
  10. | Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  11. | Written by Steve Byrne.
  12. |
  13. | This file is part of GNU Smalltalk.
  14. |
  15. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  16. | under the terms of the GNU General Public License as published by the Free
  17. | Software Foundation; either version 1, or (at your option) any later version.
  18. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  19. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  20. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  21. | details.
  22. | You should have received a copy of the GNU General Public License along with
  23. | GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  24. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  25. |
  26.  ======================================================================"
  27.  
  28.  
  29. "
  30. |     Change Log
  31. | ============================================================================
  32. | Author       Date       Change 
  33. | sbyrne     29 May 89      created.
  34. |
  35. "
  36.  
  37. Memory variableWordSubclass: #WordMemory
  38.        instanceVariableNames: ''
  39.        classVariableNames: ''
  40.        poolDictionaries: ''
  41.        category: nil.
  42.  
  43. WordMemory comment: 
  44. 'I have no instances.  I provide messages to my class that access real memory 
  45. as 32-bit words (well, really 31 bit integers).  An alternative implementation 
  46. would be to have a single instance of word memory that represented all memory, 
  47. and at: and at:put: accessor methods, but since you''d typically refer to that
  48. instance via a global variable, and since the global variable would probably be
  49. named WordMemory, the actual method invocations are exactly the same in 
  50. either case.' !
  51.  
  52.  
  53. !WordMemory class methodsFor: 'accessing'!
  54.  
  55. at: address
  56.     | value |
  57.     "### This is dependent on big-endian byte ordering..."
  58.     Bigendian 
  59.     ifTrue:
  60.         [ value _ ByteMemory at: address.
  61.           value >= 64 
  62.           ifTrue: [ ^self error: 'Word at ' , 
  63.                 address radix: 8 ,
  64.                 ' is not representable yet' ].
  65.           address + 1 to: address + 3 do:
  66.           [ :addr | value _ value * 256 + (ByteMemory at: addr) ].
  67.           ^value ]
  68.     ifFalse:
  69.         [ ^self error:
  70.           'I''m not preprared to handle little endian just yet' ].
  71. !
  72.  
  73. at: address put: value
  74.     Bigendian
  75.     ifTrue:
  76.         [ address + 3 to: address + 1 by: -1 do:
  77.           [ :addr | ByteMemory at: addr
  78.                 put: ( value \\ 256).
  79.                 value _ value // 256 ].
  80.           value < 0
  81.           ifTrue: [ value _ value negated.
  82.                 value _ value + 64.
  83.                 ByteMemory at: address put: value ]
  84.           ifFalse: [ ByteMemory at: address put: value ] ]
  85.     ifFalse:
  86.         [ ^self error:
  87.           'I''m not preprared to handle little endian just yet' ].
  88. !!
  89.